﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
namespace Lawyer.Web.ArchiveInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					string ArchiveID= Request.Params["id"];
					ShowInfo(ArchiveID);
				}
			}
		}
			
	private void ShowInfo(string ArchiveID)
	{
		Lawyer.BLL.ArchiveInfo bll=new Lawyer.BLL.ArchiveInfo();
		Lawyer.Model.ArchiveInfo model=bll.GetModel(ArchiveID);
		this.lblArchiveID.Text=model.ArchiveID;
		this.txtTitle.Text=model.Title;
		this.txtLawyerID.Text=model.LawyerID;
		this.txtCustomID.Text=model.CustomID;
		this.txtIsAgency.Text=model.IsAgency.ToString();
		this.txtAgencyID.Text=model.AgencyID;
		this.txtAgencyRate.Text=model.AgencyRate.ToString();
		this.txtStatus.Text=model.Status.ToString();
		this.txtEndDate.Text=model.EndDate.ToString();
		this.txtCreatedDate.Text=model.CreatedDate.ToString();
		this.txtCreatedBy.Text=model.CreatedBy;
		this.txtCheckedBy.Text=model.CheckedBy;
		this.txtCheckedDate.Text=model.CheckedDate.ToString();
		this.txtUpdatedDate.Text=model.UpdatedDate.ToString();
		this.txtUpdatedBy.Text=model.UpdatedBy;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtTitle.Text.Trim().Length==0)
			{
				strErr+="Title不能为空！\\n";	
			}
			if(this.txtLawyerID.Text.Trim().Length==0)
			{
				strErr+="LawyerID不能为空！\\n";	
			}
			if(this.txtCustomID.Text.Trim().Length==0)
			{
				strErr+="CustomID不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtIsAgency.Text))
			{
				strErr+="IsAgency格式错误！\\n";	
			}
			if(this.txtAgencyID.Text.Trim().Length==0)
			{
				strErr+="AgencyID不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtAgencyRate.Text))
			{
				strErr+="AgencyRate格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtStatus.Text))
			{
				strErr+="Status格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtEndDate.Text))
			{
				strErr+="EndDate格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreatedDate.Text))
			{
				strErr+="CreatedDate格式错误！\\n";	
			}
			if(this.txtCreatedBy.Text.Trim().Length==0)
			{
				strErr+="CreatedBy不能为空！\\n";	
			}
			if(this.txtCheckedBy.Text.Trim().Length==0)
			{
				strErr+="CheckedBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCheckedDate.Text))
			{
				strErr+="CheckedDate格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtUpdatedDate.Text))
			{
				strErr+="UpdatedDate格式错误！\\n";	
			}
			if(this.txtUpdatedBy.Text.Trim().Length==0)
			{
				strErr+="UpdatedBy不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string ArchiveID=this.lblArchiveID.Text;
			string Title=this.txtTitle.Text;
			string LawyerID=this.txtLawyerID.Text;
			string CustomID=this.txtCustomID.Text;
			int IsAgency=int.Parse(this.txtIsAgency.Text);
			string AgencyID=this.txtAgencyID.Text;
			decimal AgencyRate=decimal.Parse(this.txtAgencyRate.Text);
			int Status=int.Parse(this.txtStatus.Text);
			DateTime EndDate=DateTime.Parse(this.txtEndDate.Text);
			DateTime CreatedDate=DateTime.Parse(this.txtCreatedDate.Text);
			string CreatedBy=this.txtCreatedBy.Text;
			string CheckedBy=this.txtCheckedBy.Text;
			DateTime CheckedDate=DateTime.Parse(this.txtCheckedDate.Text);
			DateTime UpdatedDate=DateTime.Parse(this.txtUpdatedDate.Text);
			string UpdatedBy=this.txtUpdatedBy.Text;


			Lawyer.Model.ArchiveInfo model=new Lawyer.Model.ArchiveInfo();
			model.ArchiveID=ArchiveID;
			model.Title=Title;
			model.LawyerID=LawyerID;
			model.CustomID=CustomID;
			model.IsAgency=IsAgency;
			model.AgencyID=AgencyID;
			model.AgencyRate=AgencyRate;
			model.Status=Status;
			model.EndDate=EndDate;
			model.CreatedDate=CreatedDate;
			model.CreatedBy=CreatedBy;
			model.CheckedBy=CheckedBy;
			model.CheckedDate=CheckedDate;
			model.UpdatedDate=UpdatedDate;
			model.UpdatedBy=UpdatedBy;

			Lawyer.BLL.ArchiveInfo bll=new Lawyer.BLL.ArchiveInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
